$(function() {
	$("#stop").hide();
});

var timmerID;
var realTimeID;
function start(type){
	$("#start").hide();
	$("#stop").show();
	timmerID = setInterval("monitor("+type+")",3000);  //调取函数，调取频率毫秒
	realTimeID = setInterval("realTime()",3000);  //调取函数，调取频率毫秒
}

function realTime(){
	var ajax = new $ax(Feng.ctxPath + "/realtime/monitor/my/alllist", function (data) {
		$.each(data,function(k1,v1) {
			showPop(v1);
		});
    }, function (data) {
        Feng.error("查询失败!" + data.responseJSON.message + "!");
    });
    ajax.start();
}

function showPop(json){
	var pop=new Pop(json.gName + "&nbsp;&nbsp;" + json.gType,
			"",
			"股票名:" + json.gName + "&nbsp;&nbsp;股票代码:"+json.gScode
			 + "</br>所属行业:" + json.gOwerBk + "&nbsp;&nbsp;市值:" + json.gZsz + "(亿)"
			 + "</br>控盘度:" + json.gJgcydType
			 + "</br>" + json.gDec);
}
function stop(){
	$("#start").show();
	$("#stop").hide();
	window.clearInterval(timmerID);
	window.clearInterval(realTimeID);
	timmerID = null;
	realTimeID = null;
}

function monitor(type){
	var ajax = new $ax(Feng.ctxPath + "/realtime/monitor/my/list", function (data) {
		eachHtml(data);
    }, function (data) {
        Feng.error("查询失败!" + data.responseJSON.message + "!");
    });
    ajax.set("gScode",$("#gScode").val());
    ajax.set("gTime",$("#gTime").val());
    ajax.set("type",type);
    ajax.start();
}

function eachHtml(json){
	var dashboard = "";
	$.each(json.dashboard,function(k1,v1) {
		dashboard += v1.gName + v1.gLastPx +v1.gPxChange + v1.gPxChangeRate;
	});
	$("#dashboard").html(dashboard);
	
	var dashboardd = "";
	$.each(json.dashboardd,function(k1,v1) {
		dashboardd += v1.context;
	});
	$("#dashboardd").html(dashboardd);
	var html = "<div class='row'>";
	$.each(json.gdhs,function(k1,v1) {
		if(k1 %3 ==2){
			html += "<div class='row'>";
		}
		html += "<div class='col-sm-4'><div class='ibox float-e-margins'>"
		    +"<div class='ibox-title'>"
		    +"<b>所属行业:</b><font size='2' color='red'>"+v1.gOwerBk+"&nbsp;&nbsp;<b>行业涨跌幅:</b></font>"+v1.zdf+"</br><b>代码:"+v1.gScode+"&nbsp;&nbsp;股票名:"+v1.gName+""
		    +"</br>概念属性:"+v1.gConceptBk+""
		    +"</br>资金排行:<font color='red'>"+v1.gZjgzRank+"</font>&nbsp;&nbsp;控盘度:"+v1.gJgcydType+"&nbsp;&nbsp;总市值:"+v1.gZsz+"(亿)</b></br><b>个股分析:<font color='red'>"+v1.gReason+"</font></b></div>" +
		    				"<div class='ibox-title'>"+v1.chicang+"</div>"
		    +"<div class='ibox-content'>"
		    +"<table width='100%' style='border-collapse: collapse;'>"
		    + eachRealTime(v1.realTimes)
		    +"</table>"
		    +"</div></div>"
		    +"</div>";
		if(k1 %3 ==2){
			html += "</div>";
		}
	});
	html += "</div>";
	$("#context").html(html);
}

function eachRealTime(json){
	var html = "";
	for(var realtime in json){
		html +="   <tr>"
		    +"       <td class='th-name'><font color='red'><b>"+json[realtime].gTime+"</b></font></td>"
		    +"       <td>"+json[realtime].temp+"</td>"
		    +"       <td class='th-name'>"+json[realtime].gDec+"</td>"
		    +"   </tr>";
	}
	return html;
}